import {
  Controller,
  Post,
  Body,
  Get,
  Query,
  Delete,
  Param,
  Req,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { Public } from 'src/auth/utils/public.metadata';
import { LogAction } from 'src/auth/utils/logging.metadata';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Public()
  @Post('create')
  createUser(@Body() createUserDto: CreateUserDto) {
    return this.userService.createUser(createUserDto);
  }

  @LogAction('更新个人信息')
  @Post('update')
  updateUser(@Body() updateUserDto: UpdateUserDto) {
    return this.userService.updateUser(updateUserDto);
  }

  // 发送邮箱验证码
  @Public()
  @Get('sendVerification')
  sendVerification(@Query('email') email: string) {
    return this.userService.sendEmailCode(email);
  }

  @Get('list')
  getUserList() {
    return this.userService.getUserList();
  }

  @Delete(':id')
  deleteUser(@Param('id') id: string) {
    return this.userService.deleteUser(+id);
  }

  @Get('getUserInfo')
  getUserInfo(@Req() request: AuthRequest) {
    return this.userService.getUserInfo(request.user.userId);
  }
}
